// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import path = require('path');
import fs = require('fs');
import * as vscode from 'vscode';
import { cmdInsertFileRefToActionEditor, supportFromFileExt, supportToFileExt } from './fileRefMgr';


// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

	// Use the console to output diagnostic information (console.log) and errors (console.error)
	// This line of code will only be executed once when your extension is activated
	console.log('Congratulations, your extension "fastRefFile" is now active!');

	vscode.commands.executeCommand('setContext', 'ext.supportFromFileExt', supportFromFileExt);
	vscode.commands.executeCommand('setContext', 'ext.supportToFileExt', supportToFileExt);

	let disposable = vscode.commands.registerCommand('fastRefFile.insertFileRef.importModule', (selectedFile: vscode.Uri) => {
		if (!selectedFile) return;
		cmdInsertFileRefToActionEditor(selectedFile.fsPath, "import {} from \"{RePath}\";");
	});
	context.subscriptions.push(disposable);

	disposable = vscode.commands.registerCommand('fastRefFile.insertFileRef.importDefault', (selectedFile: vscode.Uri) => {
		if (!selectedFile) return;
		cmdInsertFileRefToActionEditor(selectedFile.fsPath, "import {FromFileNameNoExt} from \"{RePath}\";");
	});
	context.subscriptions.push(disposable);

	disposable = vscode.commands.registerCommand('fastRefFile.insertFileRef.importPath', (selectedFile: vscode.Uri) => {
		if (!selectedFile) return;
		cmdInsertFileRefToActionEditor(selectedFile.fsPath, "import \"{RePath}\";");
	});
	context.subscriptions.push(disposable);

	disposable = vscode.commands.registerCommand('fastRefFile.insertFileRef.requireConst', (selectedFile: vscode.Uri) => {
		if (!selectedFile) return;
		cmdInsertFileRefToActionEditor(selectedFile.fsPath, "const {FromFileNameNoExt} = require(\"{RePath}\");");
	});
	context.subscriptions.push(disposable);

	disposable = vscode.commands.registerCommand('fastRefFile.insertFileRef.requirePath', (selectedFile: vscode.Uri) => {
		if (!selectedFile) return;
		cmdInsertFileRefToActionEditor(selectedFile.fsPath, "require(\"{RePath}\");");
	});
	context.subscriptions.push(disposable);
}

// this method is called when your extension is deactivated
export function deactivate() { }
